package com.jiangkang.lottery.util;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.style.Style0;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


public class AppPush {
////    public static final String APPID = "l1jK15tsi57qWrrV50s1vA";
////    public static final String APPKEY = "ZyKQvHNdR08hlCUVRfqsy3";
////    public static final String MASTERSECRET = "UsFPpmft7h5vWp4VT6Ac84";
//    // STEP1：获取应用基本信息
    private static String appId2 = "l1jK15tsi57qWrrV50s1vA";
    private static String appKey2 = "ZyKQvHNdR08hlCUVRfqsy3";
    private static String masterSecret2 = "UsFPpmft7h5vWp4VT6Ac84";
    private static String url2 = "http://sdk.open.api.igexin.com/apiex.htm";


    private static String appId = "T1mJJLWkZK6wR2Jy6f3pu3";
    private static String appKey =  "50mXzDU6bd9t6hoS4QW5a4";
    private static String masterSecret = "js9porwzKe6z2ZZEoXx1U8";
    private static String url = "http://sdk.open.api.igexin.com/apiex.htm";

    public static void main(String[] args) throws IOException {

        IGtPush push = new IGtPush(url, appKey, masterSecret);

        Style0 style = new Style0();
        // STEP2：设置推送标题、推送内容
        style.setTitle("jk1通知"+ LocalDateTime.now().toString());
        style.setText("通知测试");
        style.setLogo("push.png");  // 设置推送图标
        // STEP3：设置响铃、震动等推送效果
        style.setRing(true);  // 设置响铃
        style.setVibrate(true);  // 设置震动


        // STEP4：选择通知模板
        NotificationTemplate template = new NotificationTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setStyle(style);


        // STEP5：定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
        List<String> appIds = new ArrayList<String>();
        appIds.add(appId);
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 60);  // 时间单位为毫秒

        // STEP6：执行推送
        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());
        String result = ret.getResponse().get("result").toString();/*{result=PushMsgToAppTimesOverLimit}*/
        System.out.println(result);
        System.out.println(ret.getResponse().toString());
        if (result.contains("Limit"))
            System.out.println("=========================");
    }


    public String push(String lastIssue,String number) throws IOException {

        IGtPush push = new IGtPush(url, appKey, masterSecret);

        Style0 style = new Style0();
        // STEP2：设置推送标题、推送内容
        style.setTitle("本期应买: "+ lastIssue +"时间:"+LocalDateTime.now().getMinute());
        style.setText("上期连续次数: "+number);
        style.setLogo("push.png");  // 设置推送图标
        // STEP3：设置响铃、震动等推送效果
        style.setRing(true);  // 设置响铃
        style.setVibrate(true);  // 设置震动


        // STEP4：选择通知模板
        NotificationTemplate template = new NotificationTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setStyle(style);


        // STEP5：定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
        List<String> appIds = new ArrayList<String>();
        appIds.add(appId);
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 60);  // 时间单位为毫秒

        // STEP6：执行推送
        IPushResult ret = push.pushMessageToApp(message);
        String result = ret.getResponse().get("result").toString();/*{result=PushMsgToAppTimesOverLimit}*/
        System.out.println(result);
//        System.out.println(ret.getResponse().toString());
//        if (result.contains("Limit"))
//            System.out.println("=========================");
        return result;
    }

    public void push2(String lastIssue,String number) throws IOException {

        IGtPush push = new IGtPush(url2, appKey2, masterSecret2);

        Style0 style = new Style0();
        // STEP2：设置推送标题、推送内容
        style.setTitle("本期应买: "+ lastIssue +"时间:"+LocalDateTime.now().getMinute());
        style.setText("上期连续次数: "+number);
        style.setLogo("push.png");  // 设置推送图标
        // STEP3：设置响铃、震动等推送效果
        style.setRing(true);  // 设置响铃
        style.setVibrate(true);  // 设置震动


        // STEP4：选择通知模板
        NotificationTemplate template = new NotificationTemplate();
        template.setAppId(appId2);
        template.setAppkey(appKey2);
        template.setStyle(style);


        // STEP5：定义"AppMessage"类型消息对象,设置推送消息有效期等推送参数
        List<String> appIds = new ArrayList<String>();
        appIds.add(appId2);
        AppMessage message = new AppMessage();
        message.setData(template);
        message.setAppIdList(appIds);
        message.setOffline(true);
        message.setOfflineExpireTime(1000 * 60);  // 时间单位为毫秒

        // STEP6：执行推送
        IPushResult ret = push.pushMessageToApp(message);
        System.out.println(ret.getResponse().toString());
    }
}